<script setup lang="ts">
import { defineProps,ref } from 'vue';
import { useTasksStore } from "../../../store/WorkPlaceStore/useTasksStore.ts";

const tasksStore = useTasksStore()

const props = defineProps({
    id:Number,
    taskDetail:String,
    itemIndex:Number,
    status:String,
})

//判断任务完成与否
const isEnd:any = ref(null)



// 点击任务详情展现模态框
function showTask(itemIndex:any){
    //点击时先判断状态
    if(props.status === "已完成"){isEnd.value = true}else{isEnd.value = false}
    //获取模态框元素，展示模态框
    const task:any = document.getElementsByClassName("modal-box")[itemIndex]
    task.style.display = "block"
    
}

// 关闭模态框
function closeTask(itemIndex:any){
    //获取模态框元素，隐藏模态框
    const task:any = document.getElementsByClassName("modal-box")[itemIndex]
    task.style.display = "none"
}

// 点击完成任务
function completeTask(id:any){
    console.log(id)
    tasksStore.setStatus(id)
    isEnd.value = true
    closeTask(props.itemIndex)
}

</script>

<template>
    <div class="i">
        <span @click="showTask(props.itemIndex)" class="cursor-pointer">查看任务详情</span>

        <!-- 模态框 -->
         <div class="modal-box" style="display: none;">
            <div class="modal">
                <div class="modal-title"><span>任务详情</span></div>
                <div class="task-text">
                    {{ props.taskDetail }}
                </div>
                <div class="task-handle">
                    <div class="ij">
                        <a-button type="primary" :disabled=isEnd class="w" @click="completeTask(props.id)" >完成任务</a-button>
                    </div>
                    <div class="ij">
                        <a-button type="primary" class="q" @click="closeTask(props.itemIndex)">取消</a-button>
                    </div>               
                </div>

            </div>
         </div>
    </div>
</template>

<style scoped>
.modal-box{
    position: fixed;
    left:0;
    top:0;
    width:100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
    display: none;
}
.modal{
    position: fixed;
    z-index: 1;
    left:30vw;
    top:30vh;
    
    /* 让他的子div在水平方向上居中且仍然独占一行 */
    display: flex;
    flex-direction: column;
    align-items: center; 

    width:40vw;
    height:40vh;
    background-color: white;
}

.modal-title{
    height: 10%;
    font-size: 20px;
    font-weight: 600;
    margin-top: 1vh;
}
.task-text{
    height:60%;
    width: 80%;
    background: linear-gradient(to bottom, skyblue, #FFFFFF);
    margin-top:3vh;
    padding: 1vw;
}
.task-handle{
    margin-top:2vh;
    width:40%;
}

.ij{
    display: inline-block;
    width:7vw;
    padding-left: 2vw;
}
.w{
    background-color: skyblue;
}
.q{
    background-color: skyblue;
}

</style>
